package com.zat.mes.andrmes.dofun.main

import android.text.TextUtils
import android.view.View
import com.zat.mes.andrmes.R
import com.zat.mes.andrmes.base.BaseActivity
import com.zat.mes.andrmes.data.Item
import com.zat.mes.andrmes.global.CompanionType
import kotlinx.android.synthetic.main.activity_message_notif.*
import kotlinx.android.synthetic.main.layout_title.*

/**
 * 通知公告
 */
class MessageNotifActivity : BaseActivity() {


    override fun init() {
        initView()
        iniData()
    }

    private fun iniData() {

        val itemBean = intent.getParcelableExtra(CompanionType.INTENT_EXTRA_BEAN) as Item
        tVtitle.text = getString(R.string.title_message_detail)
        titleMessage.text = itemBean.title
        if (TextUtils.isEmpty(itemBean.inputEmpName)) {
            itemBean.inputEmpName = ""
        }
        nameDateMessage.text = itemBean.inputEmpName + " " + itemBean.inputDateTime
//        if ("1" == itemBean.type) {
//            statusMessage.text = getString(R.string.msg_notification)
//        } else if ("2" == itemBean.type) {
//            statusMessage.text = getString(R.string.msg_safe)
//        } else if ("3" == itemBean.type) {
//            statusMessage.text = getString(R.string.msg_activity)
//        }
        statusMessage.text = itemBean.typeName

        webMessage.setVerticalScrollBarEnabled(false);
        //content是后台返回的h5标签
        webMessage.loadDataWithBaseURL(
            null,
            getHtmlData(itemBean.content), "text/html", "utf-8", null
        );
    }

    private fun initView() {
        setContentView(R.layout.activity_message_notif)
        rlReturnTitle.visibility = View.VISIBLE
        rlReturnTitle.setOnClickListener { finish() }

    }

    /**
     * 加载html标签
     *
     * @param bodyHTML
     * @return
     */
    private fun getHtmlData(bodyHTML: String?): String? {
        val head = "<head>" +
                "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\"> " +
                "<style>img{max-width: 100%; width:auto; height:auto!important;}</style>" +
                "</head>"
        return "<html>$head<body>$bodyHTML</body></html>"
    }
}
